const express = require('express')
const router = express.Router();

const db = [];

router.get('/', (req, res, next) => {
  const { url, method, query } = req;
  // 返回给前端的东西  views路径已经帮助拼接成功了，所以咱们只需要写文件名字就可以了
  res.render('login', {
    title: '少年不知愁滋味',
    data: [
      {
        city: "上海",
        code: 0000
      },
      {
        city: "北京",
        code: 1111
      }
    ]
  })
})

router.post('/api/login', (req, res, next) => {
  // 在post接口中 获取参数 req.body
  // post参数必须通过中间件的解析
  const { body, method } = req;
  db.push(body)
  res.send({
    code: 0,
    msg: 'success',
    token: body
  })
})

router.get('/list', (req, res, next) => {
  res.send(db)
})

module.exports = router;